<?
include("includes/config.inc.php");
include("includes/auth.lib.php");
include("includes/product_new.class.php");
$ftp_host = '193.254.241.55';
$ftp_username = 'usrarredo';
$ftp_pwd = 'ar15comno';
$path = $_SERVER['DOCUMENT_ROOT']."/gestione/imgs_prodotti/";
$path1 = $_SERVER['DOCUMENT_ROOT']."/immagini-piscine/";
$elenco = category::getChild(3,"0");
$qry = "SELECT idarticolo,image_tmb,image,image_big,import FROM articoli_new WHERE cid IN ($elenco);";
$rs = $conn->Execute($qry);
if($rs->RecordCount()>0) {
	$connect = ftp_connect($ftp_host);
	$login = ftp_login($connect, $ftp_username, $ftp_pwd);
	$i = 0;
	$num = $rs->RecordCount();
	$error = "";
	while(!$rs->EOF) {
		if($rs->Fields("import")==1) {
			if(file_exists($path1.$rs->Fields("image_tmb"))) {
			  	if (ftp_put($connect, "httpdocs/immagini-giardino/".$rs->Fields("image_tmb"), $path1.$rs->Fields("image_tmb"), FTP_BINARY)) {
			  		$i++;
			  	} else {
			  		$error .= $rs->Fields("idarticolo")."/".$rs->Fields("image_tmb")."<br>";
			  	}
			  }
			 if(file_exists($path1.$rs->Fields("image"))) {
			  	if (ftp_put($connect, "httpdocs/immagini-giardino/".$rs->Fields("image"), $path1.$rs->Fields("image"), FTP_BINARY)) {
			  		$i++;
			  	} else {
			  		$error .= $rs->Fields("idarticolo")."/".$rs->Fields("image")."<br>";
			  	}
			  }
			 if(file_exists($path1.$rs->Fields("image_big"))) {
			  	if (ftp_put($connect, "httpdocs/immagini-giardino/".$rs->Fields("image_big"), $path1.$rs->Fields("image_big"), FTP_BINARY)) {
			  		$i++;
			  	} else {
			  		$error .= $rs->Fields("idarticolo")."/".$rs->Fields("image_big")."<br>";
			  	}
			  }
		} else {
			if(@ftp_mkdir($connect, "httpdocs/gestione/imgs_prodotti/".$rs->Fields("idarticolo"))) {
			  ftp_site($connect, "CHMOD 0777 httpdocs/gestione/imgs_prodotti/".$rs->Fields("idarticolo"));
			  if(file_exists($path.$rs->Fields("idarticolo")."/".$rs->Fields("image_tmb"))) {
			  	if (ftp_put($connect, "httpdocs/gestione/imgs_prodotti/".$rs->Fields("idarticolo")."/".$rs->Fields("image_tmb"), $path.$rs->Fields("idarticolo")."/".$rs->Fields("image_tmb"), FTP_BINARY)) {
			  		$i++;
			  	} else {
			  		$error .= $rs->Fields("idarticolo")."/".$rs->Fields("image_tmb")."<br>";
			  	}
			  }
			 if(file_exists($path.$rs->Fields("idarticolo")."/".$rs->Fields("image"))) {
			  	if (ftp_put($connect, "httpdocs/gestione/imgs_prodotti/".$rs->Fields("idarticolo")."/".$rs->Fields("image"), $path.$rs->Fields("idarticolo")."/".$rs->Fields("image"), FTP_BINARY)) {
			  		$i++;
			  	} else {
			  		$error .= $rs->Fields("idarticolo")."/".$rs->Fields("image")."<br>";
			  	}
			  }
			 if(file_exists($path.$rs->Fields("idarticolo")."/".$rs->Fields("image_big"))) {
			  	if (ftp_put($connect, "httpdocs/gestione/imgs_prodotti/".$rs->Fields("idarticolo")."/".$rs->Fields("image_big"), $path.$rs->Fields("idarticolo")."/".$rs->Fields("image_big"), FTP_BINARY)) {
			  		$i++;
			  	} else {
			  		$error .= $rs->Fields("idarticolo")."/".$rs->Fields("image_big")."<br>";
			  	}
			  }
			}
		}
		$rs->MoveNext();
	}
	ftp_quit($connect);  
	$rs->Close();
}
die($error);
?>